//
// @Author: Zhenwei Xiao
// @Description:
// @Version: 1.0.0
// @Date: 2021/4/9 上午9:58
// @Copyright: MIN-Group；国家重大科技基础设施——未来网络北大实验室；深圳市信息论与未来网络重点实验室
//

//
// @Description: 超时事件
//
class TimeoutEvent {
    constructor() {
        this.key = ""
        this.timeoutTime = BigInt(0)
    }
    // key         string // 重组器哈希表的key
    // timeoutTime int64  // 超时时间
}

//
// @Description: 超时事件堆
//
class TimeoutEventHeap extends TimeoutEvent{
    constructor() {
        super();
        this.heap = new Array()
    }

    Less(i, j) {
        return (this.heap)[i].timeoutTime < (this.heap)[j].timeoutTime
    }

    Len() {
        return this.heap.length
    }

    Swap(i, j) {
        // Q: tmp无法解析？
        let tmp = (this.heap)[i]
        (this.heap)[i] = (this.heap)[j]
        (this.heap)[j] = tmp
    }

    Push(val) {
        (this.heap).push(val)
    }

    Pop()  {
        let old = this.heap
        this.heap = old.slice(0,old.length - 1)
        return old.pop()
    }
}

module.exports = {
    TimeoutEvent:TimeoutEvent,
    TimeoutEventHeap: TimeoutEventHeap
}

